<?php
session_start();

if (!isset($_SESSION['AdminId']) || $_SESSION['AdminId'] == "") {
    echo "<script type='text/javascript'>location.href='admin.php'</script>";
}

require_once 'common/config.php';
require_once 'common/conn.php';
require_once 'common/function.php';

require_once 'db/itemType.db.php';

$dbc = new DBC();

$itemTypeDb = new ItemTypeDb($dbc);
$array = $itemTypeDb->getItemType();

$dbc->close();
?>
<!DOCTYPE html>
<html>
    <head>
        <title>已审核老师列表</title>
        <meta charset="UTF-8">
        <link href="<?php echo $flatUi; ?>dist/css/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
        <script src="<?php echo $flatUi; ?>js/jquery-1.11.3.js"></script>
        <script type="text/javascript">

            $().ready(function() {
                btnClickHandler();
            });

            function btnClickHandler() {
                $(".btn").click(function() {
                    var idStr = $(this).attr("id");
                    if (idStr.indexOf("edit_") != -1) {
                        var id = idStr.replace("edit_", "");
                        location.href = "item_type_edit.php?id=" + id;
                    } else if (idStr.indexOf("delete_") != -1) {
                        var id = idStr.replace("delete_", "");
                        if (confirm("确定删除" + $(this).attr("name") + "?")) {
                            location.href = "action/itemType.action.php?action=delete&idx=" + id;
                        }
                    } else if (idStr.indexOf("create") != -1) {
                        location.href = "item_type_edit.php";
                    }
                });
            }

            function showdialog(url) {
                window.showModalDialog(url, "", 'edge: Raised; center: Yes; resizable: No; status: No;dialogHeight:677px;dialogWidth:375px');
            }
        </script>
    </head>
    <body>
        <div style="text-align: right"><input id="create" type="button" class="btn btn-default" value="增加商品分类"/></div>
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>类型</th>
                    <th>编辑</th>
                    <th>删除</th>
                </tr>
            </thead>
            <tbody id="tbody">
                <?php
                for ($i = 0; $i < count($array); $i++) {
                    $j = $i + 1;
                    $itemType = $array[$i];
//                    $itemTypeName = mb_convert_encoding($itemType['item_type'], "UTF-8", "GBK");
                    $itemTypeName = $itemType['item_type'];
                    ?>
                    <tr>
                        <td><?php echo $j; ?></td>
                        <td><?php echo $itemTypeName; ?></td>
                        <td><input id="edit_<?php echo $itemType['id_x']; ?>" type="button" class="btn btn-primary" value="编辑"/></td>
                        <td><input id="delete_<?php echo $itemType['id_x']; ?>" name="<?php echo $itemTypeName; ?>" type="button" class="btn btn-danger" value="删除"/></td>
                    </tr>
                <?php } ?>
                <tr id="bottom_tr"></tr>
            </tbody>
        </table>
    </body>
</html>